package org.jypj.dev.service.impl;


import java.util.*;

import javax.annotation.Resource;

import org.jypj.dev.util.StringUtil;
import org.springframework.stereotype.Service;
import org.jypj.dev.model.TrainStation;
import org.jypj.dev.dao.ITrainStationDao;
import org.jypj.dev.service.ITrainStationService;
import org.jypj.dev.util.Page;

@Service("trainStationService")
public class TrainStationServiceImpl implements ITrainStationService {

    @Resource
    private ITrainStationDao trainStationDao;

    /**
     * 保存
     * 所有字段全都保存
     *
     * @param trainStation
     * @return 保存后的对象包括ID
     */
    public int saveTrainStation(TrainStation trainStation) {
        if (StringUtil.isEmpty(trainStation.getId())) {
            String uuid = UUID.randomUUID().toString().replace("-", "").trim();
            trainStation.setId(uuid);
        }
        return trainStationDao.saveTrainStation(trainStation);
    }

    /**
     * 根据ID删除
     *
     * @param id 主键ID
     * @return 删除记录数
     */
    public int deleteTrainStationById(String id) {

        return trainStationDao.deleteTrainStationById(id);
    }

    /**
     * 根据对象删除
     *
     * @param trainStation
     * @return
     */
    public int deleteTrainStationByObject(TrainStation trainStation) {

        return trainStationDao.deleteTrainStationByObject(trainStation);
    }

    /**
     * 更新
     * 更新所有字段
     *
     * @param trainStation
     * @return 保存后的对象包括ID
     */
    public int updateTrainStation(TrainStation trainStation) {

        return trainStationDao.updateTrainStation(trainStation);
    }

    /**
     * 按ID查询
     *
     * @return TrainStation
     * @parm id 主键ID
     */
    public TrainStation selectTrainStationById(String id) {

        return trainStationDao.selectTrainStationById(id);
    }

    /**
     * 分页查询 包含条件
     *
     * @param page 分页对象
     * @param map  查询条件
     * @return List<TrainStation>
     */
    public Page selectOnePageByMap(Page page, Map<String, Object> map) {
        List<TrainStation> trainStations = trainStationDao.selectOnePageByMap(page, map);
        if (trainStations != null && trainStations.size() > 0) {
            page.setResult(trainStations);
        } else {
            page.setResult(new ArrayList<TrainStation>());
        }
        return page;
    }

    /**
     * 分页查询 包含对象条件
     *
     * @param page         分页对象
     * @param trainStation 查询条件
     * @return Page
     */
    public Page selectOnePageByTrainStation(Page page, TrainStation trainStation) {
        List<TrainStation> trainStations = trainStationDao.selectOnePageByTrainStation(page, trainStation);
        if (trainStations != null && trainStations.size() > 0) {
            page.setResult(trainStations);
        } else {
            page.setResult(new ArrayList<TrainStation>());
        }
        return page;
    }

    /**
     * 按条件查询全部的
     *
     * @param map 查询条件
     * @return List<TrainStation>
     */
    public List<TrainStation> selectAllByMap(Map<String, Object> map) {
        return trainStationDao.selectAllByMap(map);
    }

    @Override
    public List<TrainStation> selectAllStation(Map<String, Object> map) {

        return trainStationDao.selectAllStation(map);
    }


    /**
     * 按条件查询全部的
     *
     * @param trainStation 查询条件
     * @return List<TrainStation>
     */
    public List<TrainStation> selectAllByTrainStation(TrainStation trainStation) {

        return trainStationDao.selectAllByTrainStation(trainStation);
    }

    /**
     * 按条件查询单个对象
     *
     * @param map 查询条件
     * @return TrainStation
     */
    public TrainStation selectObjectByMap(Map<String, Object> map) {

        return trainStationDao.selectObjectByMap(map);
    }

    /**
     * 按条件查询单个对象
     *
     * @param trainStation 查询条件
     * @return TrainStation
     */
    public TrainStation selectObjectByTrainStation(TrainStation trainStation) {

        return trainStationDao.selectObjectByTrainStation(trainStation);
    }

    /**
     * 按车次ID查询
     *
     * @param trainId
     * @return
     */
    public List<TrainStation> selectTrainStationsByTrainId(String trainId) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("trainId", trainId);
        return trainStationDao.selectAllByMap(queryMap);
    }
}